﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Acme
{
    public class MouseController : IMouseControl
    {
        private IMouseModel Model;
        private IMouseView View;

        public MouseController(IMouseView view, IMouseModel model)
        {
            this.View = view;
            this.Model = model;
            // wire up everything
            this.View.RequestToFeedRodent += new EventHandler(View_RequestToFeedRodent);
            this.Model.ModelUpdated += this.View.UpdateView;
            // tell model to update it's listeners
            this.Model.UpdateListeners();
        }

        void View_RequestToFeedRodent(object sender, EventArgs e)
        {
            FeedRodent(this.View.GetAmountToFeedRodent());
        }

        public void FeedRodent(int pAmount)
        {
            this.Model.Feed(pAmount);

            if (this.Model.TotalFoodEaten >= this.Model.MaxFeed)
                this.View.DisableFeeding();
        }

     }
}
